package com.aios.action.timer;
import org.apache.log4j.Logger;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import com.aios.entity.Switch;
import com.aios.entity.SwitchPanel;
import com.aios.service.SwitchPanelService;
public class TimerAddAction extends AbstractTimerAction {

	private static final long serialVersionUID = 1L;
	private static Logger logger = Logger.getLogger(TimerAddAction.class);
	private List<Switch> switchList;
	@Qualifier("switchPanelService")
	@Autowired	protected SwitchPanelService switchPanelService;

	public List<SwitchPanel> getSwitchPanelList() {
		return switchPanelList;
	}

	public void setSwitchPanelList(List<SwitchPanel> switchPanelList) {
		this.switchPanelList = switchPanelList;
	}

	public String getPanelId() {
		return panelId;
	}

	public void setPanelId(String panelId) {
		this.panelId = panelId;
	}

	private List<SwitchPanel> switchPanelList;
	private String panelId;

	public List<Switch> getSwitchList() {
		return switchList;
	}

	public void setSwitchList(List<Switch> switchList) {
		this.switchList = switchList;
	}

	public String execute() {
		setMode(Mode.ADD);
		if(actionMessage !=null && actionMessage !=""){
			addActionMessage(actionMessage);
		}
		try {
			populateHourList();
			populateMinList();
			setSettingList();
			populateWeekList();
			populateSelectedDays();

			switchPanelList = switchPanelService
					.findByUserId(getSessionUserVariable().getId());

			if (switchPanelList == null || switchPanelList.size() == 0) {
				actionError = getText("switch.error.panel.not.exist");
				return INPUT;
			} else if (switchPanelList.size() == 1) {
				panelId = switchPanelList.get(0).getId();
				switchList = switchService
						.findAllBySwitchPanelId(switchPanelList.get(0).getId());
			} else if (switchPanelList.size() > 1) {
				// use when multiple switch panels available for one user.
			}
		} catch (Exception e) {
			logger.error(e);
			e.printStackTrace();
		}
		return SUCCESS;
	}

	public TimerAddAction() {

	}

}
